@extends('layouts/admin')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{ asset('resources/org/uploadify/uploadify.css') }}">
    <script src="{{ asset('resources/org/uploadify/jquery.uploadify.min.js') }}" type="text/javascript"></script>

    <script type="text/javascript" src="{{ asset('resources/org/ueditor/ueditor.config.js') }}"></script>
    <script type="text/javascript" src="{{ asset('resources/org/ueditor/ueditor.all.min.js') }}"></script>
    <script type="text/javascript" charset="utf-8" src="{{ asset('resources/org/ueditor/lang/zh-cn/zh-cn.js') }}"></script>
    <style type="text/css">
        .edui-default{line-height: 28px;}
        div.edui-combox-body,div.edui-button-body,div.edui-splitbutton-body
        {overflow: hidden; height:20px;}
        div.edui-box{overflow: hidden; height:22px;}

        .uploadify{display:inline-block;}
        .uploadify-button{border:none; border-radius:5px; margin-top:8px;}
        table.add_tab tr td span.uploadify-button-text{color: #FFF; margin:0;}
    </style>
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{url('admin/info')}}">首页</a> &raquo; <a href="{{url('admin/article')}}">文章管理</a> &raquo; 添加文章
    </div>
    <!--面包屑导航 结束-->

	<!--结果集标题与导航组件 开始-->
	<div class="result_wrap">
        <div class="result_title">
            <h3>文章管理操作</h3>
            @if(isset($errors) && count($errors) > 0)
                <div class="mark">
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <p>{{  $error }}</p>
                        @endforeach
                    @else
                        <p>{{ $errors }}</p>
                    @endif
                </div>
            @endif
        </div>
        <div class="result_content">
            <div class="short_wrap">
                <a href="{{url('admin/article/create')}}"><i class="fa fa-plus"></i>新增文章</a>
                <a href="{{url('admin/article')}}"><i class="fa fa-recycle"></i>文章列表</a>
            </div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->

    <div class="result_wrap">
        <form action="{{url('admin/article')}}" method="post">
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th width="120"><i class="require">*</i>文章分类：</th>
                        <td>
                            <select name="cate_id">
                                @foreach($data as $v)
                                <option value="{{ $v->cate_id }}">{{ $v->html . $v->cate_name }}</option>
                                @endforeach
                            </select>
                            {{csrf_field()}}
                        </td>
                    </tr>

                    <tr>
                        <th><i class="require">*</i>文章标题：</th>
                        <td>
                            <input type="text" class="lg" name="art_title">
                            <span><i class="fa fa-exclamation-circle yellow"></i>这里必须输入内容</span>
                        </td>
                    </tr>
                    <tr>
                        <th>文章标签：</th>
                        <td>
                            <input type="text" class="lg" name="art_tag">
                            <p>可以输入多个标签，每个标签用(英文逗号或空格), 隔开</p>
                        </td>
                    </tr>
                    <tr>
                        <th>文章缩略图：</th>
                        <td>
                            <input type="text" size="50" name="art_thumb">
                            <input type="file" id="file_upload" />
                            <p>这里面上传缩略图</p>
                        </td>
                    </tr>

                    <tr>
                        <th height="auto"></th>
                        <td><img id="art_thumb_img" src="" alt="" style="max-width: 300px;;max-height: 100px;"></td>
                    </tr>

                    <tr>
                        <th height="auto">文章描述：</th>
                        <td>
                            <textarea name="art_description"></textarea>
                        </td>
                    </tr>

                    <tr>
                        <th>文章内容：</th>
                        <td>
                            <textarea id="editor" name="art_content" style="width:860px;height:500px;"></textarea>
                        </td>
                    </tr>

                    <tr>
                        <th>文章查看次数：</th>
                        <td>
                            <input type="text" class="lg" name="art_view" value="100">
                            <p>这里面输入查看次数</p>
                        </td>
                    </tr>
                    <tr>
                        <th>文章编辑：</th>
                        <td>
                            <input type="text" name="art_editor" value="admin">
                            <p>这里面输入编辑名称</p>
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <input type="submit" value="提交">
                            <input type="button" class="back" onclick="history.go(-1)" value="返回">
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <script type="text/javascript">
        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        var ue = UE.getEditor('editor');

        <?php $timestamp = time();?>
		$(function() {
            $('#file_upload').uploadify({
                'formData'     : {
                    'timestamp' : '<?php echo $timestamp;?>',
                    '_token'     : '{{ csrf_token() }}'
                },
                'buttonText' : '上传图片',
                'swf'      : '{{ asset('resources/org/uploadify/uploadify.swf') }}',
                'uploader' : '{{ url('admin/upload') }}',
                'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                    alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
                },
                'onUploadSuccess' : function(file, data, response) {
                    var datap = JSON.parse(data); //$.parseJSON(data);
                    layer.msg(datap.msg);
                    if(datap.errno == 0) {
                        $("input[name='art_thumb']").val(datap.path);
                        $('#art_thumb_img').attr('src', '/' + datap.path);
                    }
                }
            });
        });

    </script>
@endsection